package com.crm.web.controller.business;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.crm.common.annotation.Log;
import com.crm.common.enums.BusinessType;
import com.crm.system.domain.BieDoctor;
import com.crm.system.service.IBieDoctorService;
import com.crm.common.core.controller.BaseController;
import com.crm.common.core.domain.AjaxResult;
import com.crm.common.utils.poi.ExcelUtil;
import com.crm.common.core.page.TableDataInfo;

/**
 * 医护人员Controller
 * 
 * @author crm
 * @date 2021-05-10
 */
@Controller
@RequestMapping("/system/doctor")
public class BieDoctorController extends BaseController
{
    private String prefix = "system/doctor";

    @Autowired
    private IBieDoctorService bieDoctorService;

    @RequiresPermissions("system:doctor:view")
    @GetMapping()
    public String doctor()
    {
        return prefix + "/doctor";
    }

    /**
     * 查询医护人员列表
     */
    @RequiresPermissions("system:doctor:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BieDoctor bieDoctor)
    {
        startPage();
        List<BieDoctor> list = bieDoctorService.selectBieDoctorList(bieDoctor);
        return getDataTable(list);
    }

    /**
     * 导出医护人员列表
     */
    @RequiresPermissions("system:doctor:export")
    @Log(title = "医护人员", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BieDoctor bieDoctor)
    {
        List<BieDoctor> list = bieDoctorService.selectBieDoctorList(bieDoctor);
        ExcelUtil<BieDoctor> util = new ExcelUtil<BieDoctor>(BieDoctor.class);
        return util.exportExcel(list, "医护人员数据");
    }

    /**
     * 新增医护人员
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存医护人员
     */
    @RequiresPermissions("system:doctor:add")
    @Log(title = "医护人员", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BieDoctor bieDoctor)
    {
        return toAjax(bieDoctorService.insertBieDoctor(bieDoctor));
    }

    /**
     * 修改医护人员
     */
    @GetMapping("/edit/{doctorId}")
    public String edit(@PathVariable("doctorId") String doctorId, ModelMap mmap)
    {
        BieDoctor bieDoctor = bieDoctorService.selectBieDoctorById(doctorId);
        mmap.put("bieDoctor", bieDoctor);
        return prefix + "/edit";
    }

    /**
     * 修改保存医护人员
     */
    @RequiresPermissions("system:doctor:edit")
    @Log(title = "医护人员", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BieDoctor bieDoctor)
    {
        return toAjax(bieDoctorService.updateBieDoctor(bieDoctor));
    }

    /**
     * 删除医护人员
     */
    @RequiresPermissions("system:doctor:remove")
    @Log(title = "医护人员", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(bieDoctorService.deleteBieDoctorByIds(ids));
    }
}
